package org.yabam.model;

import java.util.List;

import org.yabam.dao.DAOFactory;
import org.yabam.dao.DefaultDAO;

public class Category {

	private long id;
	private String name;
	private Category parent;

	private final static DefaultDAO<Category> dao = DAOFactory.getCategoryDAO();

	/**
	 * @param id
	 * @param name
	 */
	public Category(long id, String name, Category parent) {
		super();
		this.id = id;
		this.name = name;
		this.parent = parent;
	}

	public Category() {}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the parent
	 */
	public Category getParent() {
		return parent;
	}

	/**
	 * @param parent
	 *            the parent to set
	 */
	public void setParent(Category parent) {
		this.parent = parent;
	}

	/**
	 * @param toBeDeleted
	 * @see org.yabam.dao.DefaultDAO#delete(java.lang.Object)
	 */
	public void delete() {
		dao.delete(this);
	}

	/**
	 * @param id
	 * @return
	 * @see org.yabam.dao.DefaultDAO#get(java.lang.Object)
	 */
	public static Category get(Long id) {
		return dao.get(id);
	}

	/**
	 * @return
	 * @see org.yabam.dao.DefaultDAO#getAll()
	 */
	public static List<Category> getAll() {
		return dao.getAll();
	}

	/**
	 * @param toBeSaved
	 * @see org.yabam.dao.DefaultDAO#saveOrUpdate(java.lang.Object)
	 */
	public void saveOrUpdate() {
		dao.saveOrUpdate(this);
	}

}
